<template>
  <div class="app-container">
    <!-- 添加或修改流程实例对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1000px" v-if="open" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="150px">
        <el-form-item label="审批意见" prop="message">
          <el-input v-model="form.message" type="textarea" placeholder="请输入审批意见"
                    :autosize="{minRows: 4, maxRows: 4}"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="handleBtn('审核通过')">审核通过</el-button>
        <el-button @click="handleBtn('驳回')">驳回</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { handle } from "@/api/flow/instance";

export default {
  name: "Dialog",
  data() {
    return {
      id: null,
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        message: [
          { required: true, message: "审批意见不能为空", trigger: "blur" }
        ],
      }
    };
  },
  methods: {
    /** 打开办理弹框 */
    async show(id) {
      this.reset();
      this.id = id
      this.title = "办理"
      this.open = true
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        message: null,
      };
      this.resetForm("form");
    },
    /** 审核通过按钮 */
    handleBtn(conditionValue) {
      this.$refs["form"].validate(valid => {
        if (valid) {
          handle(this.id, conditionValue, this.form.message).then(response => {
            this.$modal.msgSuccess("办理成功");
            this.open = false;
            this.$emit('refresh');
          });
        }
      });
    },
  }
};
</script>
